package com.atguigu.yygh.sms.service.impl;


import com.atguigu.yygh.common.utils.RandomUtil;
import com.atguigu.yygh.sms.service.SmsService;
import com.atguigu.yygh.vo.msm.MsmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.concurrent.TimeUnit;

@Service
public class SmsServiceImpl implements SmsService {

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public boolean sendCode(String PhoneNumber) {
//        String redisCode = redisTemplate.opsForValue().get(PhoneNumber);
        if(StringUtils.isEmpty(PhoneNumber)) return false;

        String fourBitRandom = RandomUtil.getFourBitRandom();
        System.out.println("fourBitRandom = " + fourBitRandom);
//        把验证码保存在Redis中一份
        redisTemplate.opsForValue().set(PhoneNumber,fourBitRandom,50, TimeUnit.DAYS);
        return true;
    }


    @Override
    public void sendMeaage(MsmVo msmVo) {
        String phone = msmVo.getPhone();

        System.out.println("给就诊人发送短信提示成功");
    }

}
